package script.db

databaseChangeLog(logicalFilePath: 'script/db/hpfm_cusz_model_field.groovy') {
    changeSet(author: "hzero@hand-china.com", id: "2022-07-01-hpfm_cusz_model_field") {
        def weight = 1
        if (helper.isSqlServer()) {
            weight = 2
        } else if (helper.isOracle()) {
            weight = 3
        }
        if (helper.dbType().isSupportSequence()) {
            createSequence(sequenceName: 'hpfm_cusz_model_field_s', startValue: "1")
        }
        createTable(tableName: "hpfm_cusz_model_field", remarks: "") {
            column(name: "field_id", type: "bigint", autoIncrement: true, remarks: "表ID，主键，供其他表做外键") { constraints(primaryKey: true) }
            column(name: "model_id", type: "bigint", remarks: "关联模型ID") { constraints(nullable: "false") }
            column(name: "field_uuid", type: "varchar(" + 60 * weight + ")", remarks: "字段uuid") { constraints(nullable: "false") }
            column(name: "field_type", type: "varchar(" + 30 * weight + ")", remarks: "字段类型") { constraints(nullable: "false") }
            column(name: "field_category", type: "varchar(" + 30 * weight + ")", remarks: "字段类别") { constraints(nullable: "false") }
            column(name: "field_code", type: "varchar(" + 120 * weight + ")", remarks: "字段编码") { constraints(nullable: "false") }
            column(name: "field_name", type: "varchar(" + 120 * weight + ")", remarks: "字段描述") { constraints(nullable: "false") }
            column(name: "data_size", type: "int", remarks: "字段长度") { constraints(nullable: "false") }
            column(name: "field_multi_lang", type: "varchar(" + 1 * weight + ")", defaultValue: "0", remarks: "是否多语言字段。1是，0不是") { constraints(nullable: "false") }
            column(name: "default_value", type: "varchar(" + 240 * weight + ")", remarks: "默认值")
            column(name: "not_null", type: "varchar(" + 1 * weight + ")", defaultValue: "0", remarks: "是否必输。1是，0不是") { constraints(nullable: "false") }
            column(name: "field_primary_key", type: "varchar(" + 1 * weight + ")", defaultValue: "0", remarks: "是否主键。1是，0不是") { constraints(nullable: "false") }
            column(name: "tenant_id", type: "bigint", defaultValue: "0", remarks: "租户ID") { constraints(nullable: "false") }
            column(name: "object_version_number", type: "bigint", defaultValue: "1", remarks: "行版本号，用来处理锁") { constraints(nullable: "false") }
            column(name: "created_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "creation_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
            column(name: "last_updated_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "last_update_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
        }

        addUniqueConstraint(columnNames: "model_id,field_code", tableName: "hpfm_cusz_model_field", constraintName: "hpfm_cusz_model_field_u1")
    }
}